import Mock from 'mockjs'

//路由刷新接口
Mock.mock('/route/refresh', 'put', {
  msg: '刷新路由成功',
  timestamp: '1544663180606',
  success: true
})

//路由分页获取配置信息
Mock.mock(/\/route\/page/, 'get', {
  msg: '查询路由列表成功',
  timestamp: '1544664901945',
  data: {
    total: 12,
    size: 5,
    current: 1,
    pages: 3,
    'records': [
      {
        'id': 1,
        gmtCreate: '2018-12-13T09:27:06',
        gmtModified: '2018-12-13T09:27:06',
        deleted: false,
        routeName: 'ca-auth11',
        path: '/ca-auth/**',
        uri: 'lb://icloud-ca-auth',
        order: 0,
        'filterList|3-6': [
          {
            'id|+1': 100,
            gmtCreate: '2018-12-13T09:27:06',
            gmtModified: '2018-12-13T09:27:06',
            deleted: false,
            routeId: '10851475be044315a65baefd3e8a9ddf',
            filterName: 'StripPrefix',
            filterKey: '_genkey_0',
            filterKeyExt: null,
            filterValue: '1',
            filterValueExt: null
          }
        ]
      },
      {
        'id': 2,
        gmtCreate: '2018-12-13T09:27:06',
        gmtModified: '2018-12-13T09:27:06',
        deleted: false,
        routeName: 'ca-auth11',
        path: '/ca-auth/**',
        uri: 'lb://icloud-ca-auth',
        order: 0,
        'filterList|3-6': [
          {
            'id|+1': 100,
            gmtCreate: '2018-12-13T09:27:06',
            gmtModified: '2018-12-13T09:27:06',
            deleted: false,
            routeId: '10851475be044315a65baefd3e8a9ddf',
            filterName: 'StripPrefix',
            filterKey: '_genkey_0',
            filterKeyExt: null,
            filterValue: '1',
            filterValueExt: null
          }
        ]
      }
    ]
  },
  success: true
})

//查看路由信息,根据路由id
Mock.mock(/\/route\//, 'get', {
  code: 0,
  state: 200,
  msg: '查询路由列表成功',
  timestamp: '1544668508754',
  data: {
    'id|1-10': '14',
    gmtCreate: '2018-12-13T09:27:04',
    gmtModified: '2018-12-13T09:27:04',
    deleted: false,
    routeName: 'ca-auth10',
    path: '/ca-auth/**',
    uri: 'lb://icloud-ca-auth',
    order: 0,
    'filterList|3': [
      {
        'id|1-12': '1',
        gmtCreate: '2018-12-13T09:27:03',
        gmtModified: '2018-12-13T09:27:03',
        deleted: false,
        routeId: '5baf95f37bae463bb3919744db8c9fb1', //路由器唯一标识
        filterName: 'StripPrefix', //过滤器名称
        filterKey: '_genkey_0', //过滤器key值
        filterValue: '1', //过滤器value值
        filterKeyExt: null, //过滤器扩展信息key
        filterValueExt: null //过滤器扩展信息值
      }
    ]
  },
  success: true
})

//新增路由信息
Mock.mock('/route', 'post', {
  code: 0,
  state: 200,
  msg: '添加路由成功',
  timestamp: '1544664426271',
  data: null,
  success: true
})

//修改路由信息
Mock.mock('/route', 'put', {
  code: 0,
  state: 200,
  msg: '更新路由成功',
  timestamp: '1544539822064',
  data: null,
  success: true
})

//删除路由，根据路由id
Mock.mock(/\/route/, 'delete', {
  code: 0,
  state: 200,
  msg: '删除路由成功',
  timestamp: '1544664319945',
  data: null,
  success: true
})

//新增过滤器，根据路由id
Mock.mock('/filter', 'post', option => {
  console.log(JSON.parse(option.body))
  return Mock.mock({
    code: 0,
    state: 200,
    msg: '添加路由过滤器成功',
    timestamp: '1544540042894',
    data: null,
    success: true
  })
})

//修改过滤器，根据路由id，根据过滤器id
Mock.mock('/filter', 'put', {
  code: 0,
  state: 200,
  msg: '更新过滤器成功',
  timestamp: '1544540114849',
  data: null,
  success: true
})

//删除过滤器，根据过滤器id或根据路由id
Mock.mock(/\/filter/, 'delete', {
  code: 0,
  state: 200,
  msg: '删除过滤器成功',
  timestamp: '1544539956740',
  data: null,
  success: true
})

//验证配置路由信息是否正确
Mock.mock('/actuator/gateway/routes', 'get', option => {
  // console.log(option)
  return {
    code: 0,
    state: 200,
    msg: '配置路由信息正确',
    timestamp: '1544539956740'
  }
})
